//
//  ViewController.m
//  坐标系转换
//
//  Created by J on 15/11/22.
//  Copyright © 2015年 J. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,weak)UIView * blue;
@property(nonatomic,weak)UIView * red;
@property(nonatomic,weak)UIView * yellow;
@property(nonatomic,weak)UIView * purple;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //蓝色
    UIView * blue = [[UIView alloc]init];
    blue.backgroundColor = [UIColor blueColor];
    blue.frame = CGRectMake(0, 50, 200, 200);
    [self.view addSubview:blue];
    self.blue = blue;
    
    //红色

    UIView * red = [[UIView alloc ]init];
    red.backgroundColor = [UIColor redColor];
    red.frame = CGRectMake(50, 60, 100, 100);
    [blue addSubview:red];
    self.red = red;
    
    
    
    UIView * yellow = [[UIView alloc ]init];
    yellow.backgroundColor = [UIColor yellowColor];
    yellow.frame = CGRectMake(10, 10, 50, 50);
    [red addSubview:yellow];
    self.yellow = yellow;
    
    
    //紫色
    UIView * purple = [[UIView alloc ]init];
    purple.backgroundColor = [UIColor purpleColor];
    purple.frame = CGRectMake(150, 350, 100, 100);
    [self.view addSubview:purple];
    self.purple = purple;
    
    

    

}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    //计算self.yellow在self.red控件中的位置和尺寸
//   CGRect newFrame =  [self.yellow.superview convertRect:self.yellow.frame toView:self.red];
//    CGRect newFrame =  [self.yellow convertRect:self.yellow.bounds toView:self.view];
//    计算self.red在self.yellow的位置和尺寸

    

//    NSLog(@"%@",NSStringFromCGRect(newFrame));
//    NSLog(@"%@",NSStringFromCGRect(self.yellow.frame));

    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
